<?php 

namespace app\admin\event;

use app\common\model\Shop;
use app\common\model\ShopApply as ShopApplyModel;
use app\common\utils\JsonService;

class ShopApplyEvent{

    /*
    * 店铺申请列表
    */
    public static function shopApplyList(){
        $params = array_filter(request()->param());
        $page = ! empty($params['page']) && $params['page'] >= 1 ? $params['page'] : 1;
        $where = [];
        if($apply_id = isset($params['apply_id'])){
                    $where[] = [['apply_id','=',$params['apply_id']]];
            }
            if($shop_id = isset($params['shop_id'])){
                    $where[] = [['shop_id','like',"%{$params['shop_id']}%"]];
            }
            if($apply_type = isset($params['apply_type'])){
                    $where[] = [['apply_type','like',"%{$params['apply_type']}%"]];
            }
            if($member_id = isset($params['member_id'])){
                    $where[] = [['member_id','like',"%{$params['member_id']}%"]];
            }
            if($company_name = isset($params['company_name'])){
                    $where[] = [['company_name','like',"%{$params['company_name']}%"]];
            }
            if($user_name = isset($params['user_name'])){
                    $where[] = [['user_name','like',"%{$params['user_name']}%"]];
            }
            if($province_id = isset($params['province_id'])){
                    $where[] = [['province_id','like',"%{$params['province_id']}%"]];
            }
            if($city_id = isset($params['city_id'])){
                    $where[] = [['city_id','like',"%{$params['city_id']}%"]];
            }
            if($district_id = isset($params['district_id'])){
                    $where[] = [['district_id','like',"%{$params['district_id']}%"]];
            }
            if($address_detail = isset($params['address_detail'])){
                    $where[] = [['address_detail','like',"%{$params['address_detail']}%"]];
            }
            if($company_type = isset($params['company_type'])){
                    $where[] = [['company_type','like',"%{$params['company_type']}%"]];
            }
            if($company_employee_count = isset($params['company_employee_count'])){
                    $where[] = [['company_employee_count','like',"%{$params['company_employee_count']}%"]];
            }
            if($company_registered_capital = isset($params['company_registered_capital'])){
                    $where[] = [['company_registered_capital','like',"%{$params['company_registered_capital']}%"]];
            }
            if($contacts_name = isset($params['contacts_name'])){
                    $where[] = [['contacts_name','like',"%{$params['contacts_name']}%"]];
            }
            if($contacts_card_no = isset($params['contacts_card_no'])){
                    $where[] = [['contacts_card_no','like',"%{$params['contacts_card_no']}%"]];
            }
            if($contacts_card_electronic_1 = isset($params['contacts_card_electronic_1'])){
                    $where[] = [['contacts_card_electronic_1','like',"%{$params['contacts_card_electronic_1']}%"]];
            }
            if($contacts_card_electronic_2 = isset($params['contacts_card_electronic_2'])){
                    $where[] = [['contacts_card_electronic_2','like',"%{$params['contacts_card_electronic_2']}%"]];
            }
            if($contacts_card_electronic_3 = isset($params['contacts_card_electronic_3'])){
                    $where[] = [['contacts_card_electronic_3','like',"%{$params['contacts_card_electronic_3']}%"]];
            }
            if($business_licence_number = isset($params['business_licence_number'])){
                    $where[] = [['business_licence_number','like',"%{$params['business_licence_number']}%"]];
            }
            if($business_sphere = isset($params['business_sphere'])){
                    $where[] = [['business_sphere','like',"%{$params['business_sphere']}%"]];
            }
            if($business_licence_number_electronic = isset($params['business_licence_number_electronic'])){
                    $where[] = [['business_licence_number_electronic','like',"%{$params['business_licence_number_electronic']}%"]];
            }
            if($organization_code = isset($params['organization_code'])){
                    $where[] = [['organization_code','like',"%{$params['organization_code']}%"]];
            }
            if($organization_code_electronic = isset($params['organization_code_electronic'])){
                    $where[] = [['organization_code_electronic','like',"%{$params['organization_code_electronic']}%"]];
            }
            if($general_taxpayer = isset($params['general_taxpayer'])){
                    $where[] = [['general_taxpayer','like',"%{$params['general_taxpayer']}%"]];
            }
            if($bank_account_name = isset($params['bank_account_name'])){
                    $where[] = [['bank_account_name','like',"%{$params['bank_account_name']}%"]];
            }
            if($bank_account_number = isset($params['bank_account_number'])){
                    $where[] = [['bank_account_number','like',"%{$params['bank_account_number']}%"]];
            }
            if($bank_name = isset($params['bank_name'])){
                    $where[] = [['bank_name','like',"%{$params['bank_name']}%"]];
            }
            if($bank_code = isset($params['bank_code'])){
                    $where[] = [['bank_code','like',"%{$params['bank_code']}%"]];
            }
            if($bank_address = isset($params['bank_address'])){
                    $where[] = [['bank_address','like',"%{$params['bank_address']}%"]];
            }
            if($bank_licence_electronic = isset($params['bank_licence_electronic'])){
                    $where[] = [['bank_licence_electronic','like',"%{$params['bank_licence_electronic']}%"]];
            }
            if($settlement_bank_account_name = isset($params['settlement_bank_account_name'])){
                    $where[] = [['settlement_bank_account_name','like',"%{$params['settlement_bank_account_name']}%"]];
            }
            if($settlement_bank_account_number = isset($params['settlement_bank_account_number'])){
                    $where[] = [['settlement_bank_account_number','like',"%{$params['settlement_bank_account_number']}%"]];
            }
            if($settlement_bank_name = isset($params['settlement_bank_name'])){
                    $where[] = [['settlement_bank_name','like',"%{$params['settlement_bank_name']}%"]];
            }
            if($settlement_bank_code = isset($params['settlement_bank_code'])){
                    $where[] = [['settlement_bank_code','like',"%{$params['settlement_bank_code']}%"]];
            }
            if($settlement_bank_address = isset($params['settlement_bank_address'])){
                    $where[] = [['settlement_bank_address','like',"%{$params['settlement_bank_address']}%"]];
            }
            if($tax_registration_certificate = isset($params['tax_registration_certificate'])){
                    $where[] = [['tax_registration_certificate','like',"%{$params['tax_registration_certificate']}%"]];
            }
            if($tax_registration_certificate_electronic = isset($params['tax_registration_certificate_electronic'])){
                    $where[] = [['tax_registration_certificate_electronic','like',"%{$params['tax_registration_certificate_electronic']}%"]];
            }
            if($taxpayer_id = isset($params['taxpayer_id'])){
                    $where[] = [['taxpayer_id','like',"%{$params['taxpayer_id']}%"]];
            }
            if($shop_name = isset($params['shop_name'])){
                    $where[] = [['shop_name','like',"%{$params['shop_name']}%"]];
            }
            if($apply_status = isset($params['apply_status'])){
                    $where[] = [['apply_status','like',"%{$params['apply_status']}%"]];
            }
            if($apply_message = isset($params['apply_message'])){
                    $where[] = [['apply_message','like',"%{$params['apply_message']}%"]];
            }
            if($shop_type_name = isset($params['shop_type_name'])){
                    $where[] = [['shop_type_name','like',"%{$params['shop_type_name']}%"]];
            }
            if($shop_type_id = isset($params['shop_type_id'])){
                    $where[] = [['shop_type_id','like',"%{$params['shop_type_id']}%"]];
            }
            if($shop_group_name = isset($params['shop_group_name'])){
                    $where[] = [['shop_group_name','like',"%{$params['shop_group_name']}%"]];
            }
            if($shop_group_id = isset($params['shop_group_id'])){
                    $where[] = [['shop_group_id','like',"%{$params['shop_group_id']}%"]];
            }
            if($paying_money_certificate = isset($params['paying_money_certificate'])){
                    $where[] = [['paying_money_certificate','like',"%{$params['paying_money_certificate']}%"]];
            }
            if($paying_money_certificate_explain = isset($params['paying_money_certificate_explain'])){
                    $where[] = [['paying_money_certificate_explain','like',"%{$params['paying_money_certificate_explain']}%"]];
            }
            if($recommend_uid = isset($params['recommend_uid'])){
                    $where[] = [['recommend_uid','like',"%{$params['recommend_uid']}%"]];
            }
             $condition = [
            'where' => $where,
            'order' => ['apply_id' => 'desc'],
                'paginate' => [
                'page' => $page,
                'query' => $params,
            ],
        ];
        $shopApply = ShopApplyModel::getPageAll($condition);
        return $shopApply;
    }


    /*
    * 新增店铺申请
    */
    public static function createShopApply($data){

        try {
            ShopApplyModel::create($data);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }

    /*
    * 更新店铺申请
    */
    public static function updateShopApply($data){
        $model = ShopApplyModel::findModel($data['apply_id'],[]);

        if($data['apply_status'] ==1){
            Shop::updateOne(['apply_status'=>$data['apply_status'],'shop_create_time'=>time()],['shop_id'=>$model['shop_id']]);
        }else{
            Shop::updateOne(['apply_status'=>$data['apply_status'],'shop_create_time'=>0],['shop_id'=>$model['shop_id']]);
        }

        try {
            ShopApplyModel::updateOne($data, ['apply_id' => $data['apply_id']]);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }


}

